﻿package mortal.game.view.copy.guildCopy
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.global.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.guild.tabpanel.*;
    import mortal.mvc.core.*;

    public class GuildCopyController extends CopyControllerBase
    {
        private var _hurtsList:GuildCopyHurtListPanel;

        public function GuildCopyController()
        {
            return;
        }// end function

        override protected function initServer() : void
        {
            super.initServer();
            return;
        }// end function

        override public function enterCopy(param1:TCopy) : void
        {
            super.enterCopy(param1);
            if (GuildCopyPanel.hasInstance() && !GuildCopyPanel.instance.isHide)
            {
                GuildCopyPanel.instance.hide();
            }
            if (GameController.guide.isViewShow)
            {
                GameController.guild.view.hide();
            }
            if (!this._hurtsList)
            {
                this._hurtsList = new GuildCopyHurtListPanel();
            }
            this._hurtsList.show(500, 500);
            this._hurtsList.x = Global.stage.stageWidth - 50 - 238;
            this._hurtsList.y = 176;
            return;
        }// end function

        override public function leaveCopy() : void
        {
            super.leaveCopy();
            if (this._hurtsList)
            {
                this._hurtsList.dispose(true);
                this._hurtsList = null;
            }
            Cache.instance.copy.guildCopy.clear();
            return;
        }// end function

        override protected function addListeners() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.GuildCopyLeftTimeUpdate, this.onUpdate);
            NetDispatcher.addCmdListener(ServerCommand.GuildCopyHurtUpdate, this.onUpdate);
            NetDispatcher.addCmdListener(ServerCommand.GuildCopyRewardUpdate, this.onUpdate);
            NetDispatcher.addCmdListener(ServerCommand.GuildCopyRewardEnd, this.onRewardEnd);
            return;
        }// end function

        override protected function removeListeners() : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.GuildCopyLeftTimeUpdate, this.onUpdate);
            NetDispatcher.removeCmdListener(ServerCommand.GuildCopyHurtUpdate, this.onUpdate);
            NetDispatcher.removeCmdListener(ServerCommand.GuildCopyRewardUpdate, this.onUpdate);
            NetDispatcher.removeCmdListener(ServerCommand.GuildCopyRewardEnd, this.onRewardEnd);
            return;
        }// end function

        private function onUpdate(param1:Object) : void
        {
            if (this._hurtsList)
            {
                this._hurtsList.updateAll();
            }
            return;
        }// end function

        private function onRewardEnd(param1:Object) : void
        {
            GuildCopyEndPanel.instance.show();
            GuildCopyEndPanel.instance.setData(param1 as SGuildBossRewardInfo);
            return;
        }// end function

    }
}
